package com.coocaa.ops.admin.v1.timedtask.job.listener;

import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.listeners.TriggerListenerSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author bijiahao
 * @description
 * @date 2020/5/13 17:50
 */
public class RealTimeOnceTriggerListener extends TriggerListenerSupport {
    private static final Logger log = LoggerFactory.getLogger(RealTimeOnceTriggerListener.class);

    private String triggerName;
    private Scheduler scheduler;

    public RealTimeOnceTriggerListener(String triggerName, Scheduler scheduler) {
        this.triggerName = triggerName;
        this.scheduler = scheduler;
    }

    @Override
    public String getName() {
        return triggerName;
    }


    @Override
    public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
        try {
            this.scheduler.pauseTrigger(trigger.getKey());
            log.info("===== triggerComplete");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
